﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using RibbonLib;
using RibbonLib.Controls;
using RibbonLib.Controls.Events;
using RibbonLib.Interop;

using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Output;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.ADF;
using ClassroomAllocationAndManagementFrame.Query;
using ClassroomAllocationAndManagementFrame.Data;

namespace ClassroomAllocationAndManagementFrame
{
    public enum RibbonMarkupCommands : uint
    {
        buttonCourseQuery = 1016,
        buttonClassroomQuery=1017,
        buttonSpareRoomQuery=1018,
        buttonNavigation=1020,
        buttonFly =1021,
        buttonZoomInOut=1022,
        buttonZoomIn=1023,
        buttonZoomOut=1024,
        buttonNarrowView=1025,
        buttonExpandView=1026,
        buttonPanView=1027,
        buttonFullExtent=1028,
        buttonIdentify=1029,
        buttonShowClassroom=1043,
        buttonShowTeachingBuilding=1044,
        button3DCampusImport=1045,
        buttonCourseImport=1046,
        buttonDeleteCommonCourseOrExam=1012
    }

    public partial class Mainform : Form, IRibbonForm
    {
        private Ribbon _ribbon = new Ribbon();
        private FormForMapControl frForMapControl = new FormForMapControl();
        private FormForSceneControl frForSceneControl = new FormForSceneControl();
        private FormForDataGridControl frForDataGridControl = new FormForDataGridControl();


        #region 定义查询窗口中的按钮

        private RibbonButton buttonCourseQuery;
        private RibbonButton buttonClassroomQuery;
        private RibbonButton buttonSpareRoomQuery;

        #endregion

        #region 定义视图窗口中的按钮

        private RibbonButton buttonFly;
        private RibbonButton buttonNavigation;
        private RibbonButton buttonZoomInOut;
        private RibbonButton buttonZoomIn;
        private RibbonButton buttonZoomOut;
        private RibbonButton buttonNarrowView;
        private RibbonButton buttonExpandView;
        private RibbonButton buttonPanView;
        private RibbonButton buttonFullExtent;
        private RibbonButton buttonIdentify;
        private RibbonButton buttonShowClassroom;
        private RibbonButton buttonShowTeachingBuilding;

        #endregion

        #region 定义数据导入导出按钮
        private RibbonButton button3DCampusImport;
        private RibbonButton buttonCourseImport;
        #endregion

        private RibbonButton buttonDeleteCommonCourseOrExam;


        public Mainform()
        {
            InitializeComponent();

            #region 实例化查询窗口中的所有按钮

            buttonCourseQuery = new RibbonButton(_ribbon, (uint)RibbonMarkupCommands.buttonCourseQuery);
            buttonCourseQuery.OnExecute += new OnExecuteEventHandler(_buttonCourseQuery_onExecute);

            buttonClassroomQuery = new RibbonButton(_ribbon, (uint)RibbonMarkupCommands.buttonClassroomQuery);
            buttonClassroomQuery.OnExecute += new OnExecuteEventHandler(_buttonClassroomQuery_onExecute);

            buttonSpareRoomQuery = new RibbonButton(_ribbon, (uint)RibbonMarkupCommands.buttonSpareRoomQuery);
            buttonSpareRoomQuery.OnExecute += new OnExecuteEventHandler(_buttonSpareRoomQuery_onExecute);

            #endregion

            #region 实例化视图窗口中的所有按钮

            buttonFly = new RibbonButton(_ribbon, (uint)RibbonMarkupCommands.buttonFly);
            buttonFly.OnExecute += new OnExecuteEventHandler(_buttonFly_OnExecute);

            buttonNavigation = new RibbonButton(_ribbon,(uint)RibbonMarkupCommands.buttonNavigation);
            buttonNavigation.OnExecute += new OnExecuteEventHandler(_buttonNavigation_OnExecute);

            buttonZoomInOut = new RibbonButton(_ribbon,(uint)RibbonMarkupCommands.buttonZoomInOut);
            buttonZoomInOut.OnExecute += new OnExecuteEventHandler(_buttonZoomInOut_OnExecute);

            buttonZoomIn = new RibbonButton(_ribbon,(uint)RibbonMarkupCommands.buttonZoomIn);
            buttonZoomIn.OnExecute += new OnExecuteEventHandler(_buttonZoomIn_OnExecute);

            buttonZoomOut = new RibbonButton(_ribbon,(uint)RibbonMarkupCommands.buttonZoomOut);
            buttonZoomOut.OnExecute += new OnExecuteEventHandler(_buttonZoomOut_OnExecute);

            buttonNarrowView = new RibbonButton(_ribbon,(uint)RibbonMarkupCommands.buttonNarrowView);
            buttonNarrowView.OnExecute +=new OnExecuteEventHandler(_buttonNarrowView_OnExecute);

            buttonExpandView = new RibbonButton(_ribbon,(uint)RibbonMarkupCommands.buttonExpandView);
            buttonExpandView.OnExecute += new OnExecuteEventHandler(_buttonExpandView_OnExecute);

            buttonPanView = new RibbonButton(_ribbon, (uint)RibbonMarkupCommands.buttonPanView);
            buttonPanView.OnExecute += new OnExecuteEventHandler(_buttonPanView_OnExecute);

            buttonFullExtent = new RibbonButton(_ribbon, (uint)RibbonMarkupCommands.buttonFullExtent);
            buttonFullExtent.OnExecute +=new OnExecuteEventHandler(_buttonFullExtent_OnExecute);

            buttonIdentify = new RibbonButton(_ribbon, (uint)RibbonMarkupCommands.buttonIdentify);
            buttonIdentify.OnExecute +=new OnExecuteEventHandler(_buttonIdentify_OnExecute);

            #endregion

            #region 实例化数据导入导出的按钮
            button3DCampusImport = new RibbonButton(_ribbon, (uint)RibbonMarkupCommands.button3DCampusImport);
            button3DCampusImport.OnExecute += new OnExecuteEventHandler(_button3DCampusImport_OnExecute);

            buttonCourseImport = new RibbonButton(_ribbon, (uint)RibbonMarkupCommands.buttonCourseImport);
            buttonCourseImport.OnExecute +=new OnExecuteEventHandler(_buttonCourseImport_OnExecute);
            #endregion

            buttonDeleteCommonCourseOrExam = new RibbonButton(_ribbon, (uint)RibbonMarkupCommands.buttonDeleteCommonCourseOrExam);
            buttonDeleteCommonCourseOrExam.OnExecute +=new OnExecuteEventHandler(_buttonDeleteCommonCourseOrExam_OnExecute);

        }

        #region 查询窗口按钮事件
        void _buttonClassroomQuery_onExecute(PropertyKeyRef key, PropVariantRef currentValue, IUISimplePropertySet commandExecutionProperties)
        {
            Form classroomquery = new FormForClassroomQuery();
            classroomquery.ShowDialog();

        }

        void _buttonSpareRoomQuery_onExecute(PropertyKeyRef key, PropVariantRef currentValue, IUISimplePropertySet commandExecutionProperties)
        {
            Form spareroomquery = new FormForSpareRoomQuery();
            spareroomquery.ShowDialog();

        }

        void _buttonCourseQuery_onExecute(PropertyKeyRef key,
            PropVariantRef currentValue,
            IUISimplePropertySet commandExecutionProperties)
        {
             Form coursequery = new FormForCourseQuery();
             coursequery.ShowDialog();
        }
        #endregion

        #region 视图窗口按钮事件
        void _buttonFly_OnExecute(PropertyKeyRef key,
            PropVariantRef currentValue,
            IUISimplePropertySet commandExecutionProperties)
        {
            frForSceneControl.FlyCommand();
        }

        void _buttonNavigation_OnExecute(PropertyKeyRef key,
            PropVariantRef currentValue,
            IUISimplePropertySet commandExecutionProperties)
        {
            frForSceneControl.NavigationCommand();
        }

        void _buttonZoomInOut_OnExecute(PropertyKeyRef key,
            PropVariantRef currentValue,
            IUISimplePropertySet commandExecutionProperties)
        {
            frForSceneControl.ZoomInOutCommand();
        }

        void _buttonZoomIn_OnExecute(PropertyKeyRef key,
            PropVariantRef currentValue,
            IUISimplePropertySet commandExecutionProperties)
        {
            frForSceneControl.ZoomInCommand();
        }

        void _buttonZoomOut_OnExecute(PropertyKeyRef key,
            PropVariantRef currentValue,
            IUISimplePropertySet commandExecutionProperties)
        {
            frForSceneControl.ZoomOutCommand();
        }

        void _buttonNarrowView_OnExecute(PropertyKeyRef key,
            PropVariantRef currentValue,
            IUISimplePropertySet commandExecutionProperties)
        {
            frForSceneControl.NarrowViewCommand();
        }

        void _buttonExpandView_OnExecute(PropertyKeyRef key,
            PropVariantRef currentValue,
            IUISimplePropertySet commandExecutionProperties)
        {
            frForSceneControl.ExpandViewCommand();
        }

        void _buttonPanView_OnExecute(PropertyKeyRef key,
            PropVariantRef currentValue,
            IUISimplePropertySet commandExecutionProperties)
        {
            frForSceneControl.PanViewCommand();
        }

        void _buttonFullExtent_OnExecute(PropertyKeyRef key,
            PropVariantRef currentValue,
            IUISimplePropertySet commandExecutionProperties)
        {
            frForSceneControl.FullExtentCommand();
        }

        void _buttonIdentify_OnExecute(PropertyKeyRef key,
            PropVariantRef currentValue,
            IUISimplePropertySet commandExecutionProperties)
        {
            frForSceneControl.IdentityCommand();
        }

        #endregion

        #region 数据导入导出的按钮事件
        void _button3DCampusImport_OnExecute(PropertyKeyRef key,
            PropVariantRef currentValue,
            IUISimplePropertySet commandExecutionProperties)
        {
             DataImport dataImport = new DataImport();
             dataImport.CampusImport();

             frForSceneControl.LoadFile(dataImport.PathForSXD);
        }

        void _buttonCourseImport_OnExecute(PropertyKeyRef key,
            PropVariantRef currentValue, IUISimplePropertySet commandExecutionProperties)
        {
            DataImport dataImport = new DataImport();
            dataImport.CourseImport();
        }
        #endregion

        void _buttonDeleteCommonCourseOrExam_OnExecute(PropertyKeyRef key,
            PropVariantRef currentValue,
            IUISimplePropertySet commandExecutionProperties)
        {
            
        }

        #region IRibbonForm Members

        public IntPtr WindowHandle
        {
            get
            {
                return this.Handle;
            }
        }

        public void RibbonHeightUpdated(int newHeight)
        {
            this.splitContainerForRibbon.SplitterDistance = newHeight;
        }

        #endregion

        private void Mainform_Load(object sender, EventArgs e)
        {
            _ribbon.InitFramework(this);

            frForMapControl.Show(this.dockPanel);
            frForMapControl.DockTo(this.dockPanel, DockStyle.Left);

            frForSceneControl.Show(this.dockPanel);
            frForSceneControl.DockTo(this.dockPanel, DockStyle.Fill);

            frForDataGridControl.Show(this.dockPanel);
            frForDataGridControl.DockTo(this.dockPanel, DockStyle.Bottom);
        }

        private void Mainform_FormClosed(object sender, FormClosedEventArgs e)
        {
            _ribbon.DestroyFramework();

            frForSceneControl.Destroy();
            frForMapControl.Destroy();
        }
    }
}
